package org.example.day07.stusys;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class StuManager {
    Map<Integer,Student> studentMap = new HashMap<>();
    Scanner input = new Scanner(System.in);
    //添加学生分数
    public void add(){
        Student student = new Student();
        System.out.println("请输入学生的ID:");
        student.setId(input.nextInt());
        System.out.println("请输入学生的分数:");
        student.setScore(input.nextInt());
        if (studentMap.containsKey(student.getId())){
            System.out.println("该学生信息已存在");
        }else {
            studentMap.put(student.getId(),student);
            System.out.println("学生分数添加成功!");
        }
    }
    //删除学生分数信息
    public void delete(){
        System.out.println("请输入删除学生的ID:");
        int id = input.nextInt();
        if (studentMap.containsKey(id)){
            studentMap.remove(id);
            System.out.println("学生分数删除成功!");
        }else
            System.out.println("学生ID录入有误!");
    }
    //显示所有学生分数信息
    public void show(){
        System.out.println("ID   \t分数");
        studentMap.forEach((k,v)->{
            System.out.println(v.getId()+"\t"+v.getScore());
        });
    }
    //菜单
    public void menu(){
        while (true){
            System.out.println("\n*****************************");
            System.out.println("1 添加学生分数信息");
            System.out.println("2 删除学生分数信息");
            System.out.println("3 所有学生分数信息");
            System.out.println("4 退出系统");
            System.out.println("*****************************\n");
            System.out.print("请选择: ");
            int num = input.nextInt();
            switch (num){
                case 1:
                    add();
                    break;
                case 2:
                    delete();
                    break;
                case 3:
                    show();
                    break;
                case 4:
                    System.out.println("退出系统!");
                    return;
                default:
                    System.out.println("菜单选择有误!!!请重新选择");
            }
        }
    }
}
